<?php
$subcat = isset($_GET['cat_id']) ? $_GET['cat_id'] : '';
$qstring = "cat_p=" . isset($_GET['cat_p']) . "&amp;cat_id=" . $subcat . "&amp;view=last_free";
$rowsPerPage = isset($_GET['num']) ? $_GET['num'] : '30';
$select = ("SELECT t1.*, t1.top_view, t3.price, t3.pid, t2.images, t2.thumbnail,t1.product_version FROM tblproduct as t1 " .
        "LEFT JOIN tblimage as t2 on t1.id=t2.product_id " .
        "INNER JOIN tblproduct_in_pharmacy as t3 on t1.id=t3.product_id " .
        "WHERE t3.status = 1 AND  t1.post_type=0 GROUP BY t1.id ORDER BY  t1.id DESC");
$result = mysql_query(getPagingQuery($select, $rowsPerPage));
$Page_list = base_url . 'product';
$pagingLink = getPagingLink($select, $rowsPerPage, $qstring, $Page_list);
$i = 1;
if (!empty($result)) {
    while ($data = mysql_fetch_assoc($result)) {
        /* get price */
        $price = mysql_query("SELECT price,regular_price FROM tblproduct_in_pharmacy WHERE product_id=" . $data['id'] . " ORDER BY price ASC LIMIT 0,1");
        $myprice = mysql_fetch_assoc($price);
        $price1 = mysql_query("SELECT price,regular_price FROM tblproduct_in_pharmacy WHERE product_id=" . $data['id'] . " ORDER BY price DESC LIMIT 0,1");
        $myprice1 = mysql_fetch_assoc($price1);
        /* end get price */
        if ($i % 4 == 1) {
            echo '<div class="row-fluid box-product">';
        }
        ?>
        <div class="span3 product_block">
            <?php
            if (!empty($cat_idp)) {
                $cat_id = $cat_idp;
            }
            if (!empty($catid)) {
                $cat_id = $catid;
            }
            echo showProduct($data, $myprice, $cat_id);
            ?>
            <span class="label <?php echo ($data[Tblproduct::product_version] == 1) ? '' : 'label-warning'; ?> prodct-type"><?php echo ($data[Tblproduct::product_version] == 1) ? $lang['PRO_STATUS_USED'] : $lang['PRO_STATUS_NEW']; ?></span>
        </div><?php
        if ($i % 4 == 0) {
            echo "</div>";
        }
        $i++;
    }
    if ($i % 4 != 1)
        echo "</div>";
} else {
    ?>
    <div class="row-fluid box-product">
        <div class="twelve columns">
            <div class="bo_eee radius1 ba_fff pad_10" style="margin-right: 15px; margin-bottom:15px;">
                <h3 align="center" style="text-align:center;">No Product in <?php echo @getCategoryName($category_id); ?> </h3>
            </div>
        </div>
    </div>
<?php }; ?>
<!--Pagination-->
<hr>
<?php if (!empty($pagingLink)) {
    ?>
    <!--     <div> -->
    <!--         <div class="span12"> -->
    <div class="box">
        <div class="pagination">
            <div class="links">
    <?php echo $pagingLink; ?>
            </div>
            <div class="clear"></div>
        </div>
    </div>
    <!--         </div> -->
    <!--     </div> -->
    <?php
}
?>
